/**
 * @author Cator Vee  hi@catorv.com
 */
let id = 0

export default {
  namespace: 'notifications',
  state: [],
  effects: {
    * sendAndWait ({payload}, {take, put}) {
      yield put({type: 'send', payload})
      return yield take('receive')
    }
  },
  reducers: {
    send (state, action) {
      return [...state, {id: ++id, ...action.payload}]
    },
    receive (state, action) {
      return state.filter(item => item.id !== action.payload)
    }
  }
}
